import { app } from 'electron'
import fs from 'fs'
import path from 'path'
import { run as nuxtRun } from '@nuxt/cli'

const isProd = app.isPackaged
const rootPath = isProd ? path.resolve(app.getAppPath(), '../../') : app.getAppPath()
const configPath = path.resolve(app.getAppPath(), 'nuxt.config.js')
const configRealPath = path.resolve(rootPath, 'nuxt.config.js')
if (!fs.existsSync(configRealPath)) {
  const config = fs.readFileSync(configPath)
  fs.writeFileSync(configRealPath, config)
}
export default () => nuxtRun(isProd ? ['start'] : undefined)
